<?php session_start();

?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<html>
<style type="text/css">
<!--
.style1 {
	color: #FF0000;
	font-weight: bold;
}
-->
</style>
<body>
<form name='dangnhap'  method="post">
		<table width='210' border='0' align='left' cellpadding='3'>
			<tr><td>Username: </td>
			<td><input name="user_name" type="text" title="Nhập tên đăng nhập.."value="<?php if(!empty($_POST['user_name']))  echo $_POST['user_name'] ;?>" size="20" style="width: 140px;"/></td></tr>
			<tr><td>Password:</td>
			<td><input name="pass_word" type="password" title="Nhập mật khẩu.." value="<?php if(!empty($_POST['pass_word'])) echo $_POST['pass_word'] ;?>" size="21" style="width: 140px;"/></td></tr>
			<tr><td colspan='2' align='center'><input type="submit" name="ok" value='Đăng nhập'/></td></tr>
  </table>
</form>

<?php

if(!empty($_POST['user_name']) && !empty($_POST['pass_word']))
{
		$id= $_POST['user_name'];
		$pass = $_POST['pass_word'];
	
		$conn=mysql_connect("localhost","root");
		if(!$conn)
		  {
		  	echo "Khong the ket noi du lieu!";
			exit;
		  }
		  mysql_select_db("qlthuvien");
  		$sql = mysql_query("select TenDangNhap,MatKhau from tblnhanvien where TenDangNhap='".$id."' and MatKhau='".md5(trim($pass))."'");
		  
		if(mysql_num_rows($sql)<>0)
		{
			mysql_close($sql);
		  	$_SESSION['id'] = $id;
			$_SESSION['pass'] = $pass;
			session_register("username"); 
			session_register("password");  

			header("Location: giaodienquanly.php");

		}
		else
				echo "<p align='center' class='style1'>Username hoặc password sai !</p>";
			
}
?>
</body>
</html>